<?php


namespace App\backend\models;

use App\common\models\BaseModel;
use Illuminate\Support\Facades\DB;

class BigWheelLogModel extends BaseModel
{
    const table = 'activity_bigwheel_log';

    static $_instance;

    const _field = ['*'];

    public static function getInstance()
    {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    /**
     * 获取数据
     * @param $condition
     * @param $page
     * @param $limit
     * @param array $field
     * @return mixed
     */
    public  function getList($condition, $page, $limit,array $field = self::_field)
    {
        return DB::table(self::table)->select($field)->where($condition)->apiPaginate($limit, ['*'], 'page', $page)->toarray();
    }

    /**
     * 获取数据数量
     * @param $condition
     * @return int
     */
    public function getCount($condition)
    {
        return DB::table(self::table)->where($condition)->count();
    }

    /**
     * 保存数据
     * @param $data
     * @return bool
     */
    public function insertSave($data)
    {
        if (!$data) {
            return '';
        }
        $data['create_time'] = time();
        return DB::table(self::table)->insert($data);
    }

    /**
     * 修改数据
     * @param $condition
     * @param $data
     * @return int|string
     */
    public function updateSave($condition, $data)
    {
        if (!$condition || !$data) {
            return '';
        }
        $data['update_time'] = time();
        return DB::table(self::table)->where($condition)->update($data);
    }

}
